package com.example.rabbitmq.demo2_deadQueue;

import com.example.rabbitmq.enums.ExchangeEnum;
import com.example.rabbitmq.enums.RoutingKeyEnum;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * @Author songyahui
 * @Date 2023/7/11 15:04
 * @Description
 */
public class Producer {

    public static void buildMessage(Channel channel) throws Exception {
        //声明交换机
        channel.exchangeDeclare(ExchangeEnum.NORMAL_EXCHANGE.name, BuiltinExchangeType.DIRECT);
        //死信消息 设置ttl时间 单位ms
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("5000").build();
//        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().build();
        for (int i = 1; i< 11;i++){
//            String message = "info-test-ttl" + i;
//            String message = "info-test-message-length" + i;
            String message = "info-test-reject" + i;
            channel.basicPublish(ExchangeEnum.NORMAL_EXCHANGE.name, RoutingKeyEnum.NORMAL.name(), properties, message.getBytes(StandardCharsets.UTF_8));
        }



//        while (scanner.hasNext()) {
//            String message = scanner.next();
//            //发送消息
//            /*
//             * 参数一: 交换机名称
//             * 参数二: 交换机路由key值
//             * 参数三: 额外参数
//             * 参数四: 消息
//             * */
//            String routingKey = null;
//            if(message.startsWith(RoutingKeyEnum.DIRECT1.name())){
//                routingKey = RoutingKeyEnum.DIRECT1.name();
//            }else {
//                routingKey = RoutingKeyEnum.DIRECT2.name();
//            }
//            channel.basicPublish(ExchangeEnum.LOGS_DIRECT.name, routingKey, null, message.getBytes(StandardCharsets.UTF_8));
//        }

    }
}
